
def tree(env, start_response):
    ancestors = env["ancestors"]
    self = env["self"]
    children = env.get("children", [])
    next = env.get("next")
    previous = env.get("previous")
    start_response("200 OK", [('Content-Type', "text/html")])
    indent = 0
    for ancestor in ancestors:
        yield link("^", ancestor, indent)
        indent+=10
    if previous:
        yield link("&lt;&lt", previous, indent)
    yield link("** <b>" + self["title"].strip()+"</b> **", None, indent)
    for child in children:
        yield link("   ++", child, indent+10)
    if next:
        yield link("&gt;&gt", next, indent)

def link(icon, D0, indent):
    anchor = ""
    if D0:
        D = {}
        D["icon"] = icon
        for (a,b) in D0.items():
            D[a] = b.strip()
        anchor = '<a href="%(url)s" title="%(title)s">%(title)s</a>' % D
    return '<div style="white-space:pre; padding-left:%s">%s %s</div>\n' % (indent, icon, anchor)
            
__wsgi__ = tree
